<html>
<?php
    require_once("menu.php");
	require_once('controllers/calendari.php');
	ini_set('display_errors', true);
	global $CALENDARIO_CAMPIONATO, $CALENDARIO_COPPA;

	//controlla se è stato passato il parametro della competizione da
	//visualizzare
	$tipo;
	$otherClassCampionato = "";
	$otherClassCoppa = "";
	$lega_id = 1;
	$cur_lega;
	/*if(isset($_GET['comp']) && filter_var($_GET['comp'], FILTER_VALIDATE_INT)){
		$tipo = (integer)$_GET['comp'];
	}else{
		$tipo = $CALENDARIO_CAMPIONATO;
	}*/
	
	
	if(isset($_GET['l']) && filter_var($_GET['l'], FILTER_VALIDATE_INT)){
		$lega_id = $_GET['l'];
	}else{
		$lega_id = Lega::getIdPrimaLega();
		
	}
	$htmlLeghe = getMenuLeghe("?", $lega_id, $cur_lega);	
	$otherClassCampionato = $cur_lega->getCompetizione()==$CALENDARIO_CAMPIONATO ? "menuSquadreSel": "";
	$otherClassCoppa = $cur_lega->getCompetizione()!=$CALENDARIO_CAMPIONATO ? "menuSquadreSel": "";
	
	function getNote($testoNote){
		if(strlen($testoNote)<=3 ) return "";		
		return "<span onmouseover=\"viewNotes($testoNote)\" onmouseout=\"hidesNotes();\" style='color:red'>*</span>";
	}

?>
	<head>
		<title>Fantacalcio - Calendario</title>
		<link rel="stylesheet" href="fantacalcio.css" type="text/css" >
		<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" >
		<script language='javascript' type='text/javascript' >
			function viewNotes(testo){
				var div = document.getElementById('divNote');
				div.style.top = cursorY + 10;
				div.style.left = cursorX - 100;
				div.innerHTML = testo;
				div.style.display='';
			}
			
			function hidesNotes(){
				var div = document.getElementById('divNote');
				div.style.display='none';
			}
			
			var cursorX;
			var cursorY;
			document.onmousemove = function(e){
			    cursorX = e.pageX;
			    cursorY = e.pageY;
			}
			
			
		</script>
	</head>
	<body>
		<table class="pageTable" cellpadding='0' cellspacing='0'>
			<tr>
				<td>
					<?php echo printMasterMenu('Calendario'); ?>
					
				</td>
				
			</tr>
			<tr>
				<td class='contentPage'>
					<table style="width:90%">
						<tr>
							<td colspan="4" class="pageTitle">Calendario della lega&nbsp;<?php echo $cur_lega->getNome(); ?> </td>
						</tr>
					</table>
					<!--<br />
					<table cellspacing='2' style="background-color: rgb(136,136,136); width:100%">
						<tr>
							<td class='menuSquadreEmpty' style='width:5%;display:'>&nbsp;</td>
							<td class='menuSquadre <?php echo $otherClassCampionato; ?>'>
								<a href='?comp=1&l= <?php echo $lega_id ?>' class='menuSquadre <?php echo $otherClassCampionato; ?>'>Campionato</a>
							</td>
							<td class='menuSquadre <?php echo $otherClassCoppa; ?> '>
								<a href='?comp=2&l= <?php echo $lega_id ?>' class='menuSquadre <?php echo $otherClassCoppa; ?> '>Coppa</a>
							</td>
							<td class='menuSquadreEmpty' style='width:75%;display:'>&nbsp;</td>
						</tr>
					</table>-->
					<br /><br />
					<table style="width:100%" cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td style="width:200px;vertical-align:top;"><?php echo  $htmlLeghe; ?></td>
							<td style="vertical-align:top;">
							<!--<div style='height:660px; width:100%; overflow-y:scroll;'>-->
								<?php
									$lastPlayedDay = 0;
									if($mobile_phone == 0 ) {echo "<div style='height:660px; width:100%; overflow-y:scroll;'>" ;}
									$calendario = Calendario::caricaCalendarioLega($lega_id);
									if($calendario->getNumGiornate() > 0){
										$tipo_calendario = $calendario->getTipo()==$CALENDARIO_CAMPIONATO ? 'CAMPIONATO' : 'COPPA';
										if($cur_lega!=null) $tipo_calendario = $tipo_calendario;
										echo "<div style='text-align:left; font-size:20px;
											color:blue;margin:10px;font-weight:bold;margin-left:20px;'>
											$tipo_calendario
											</div>";							
									}
			
									for($i=0; $i < $calendario->getNumGiornate(); $i++){
										$g = $calendario->getGiornata($i);
										if($g->getScontro(0)->getVotoCasa() > 0) $lastPlayedDay = $i;
										echo "
										<a name='giornata_$i'></a>
										<div style='margin-left:20px;margin-right:10px;'>";
										/*echo "<div style='text-align:center; font-size:15px;color:blue;'>" .
											$calendario->getTipo() . "</div>";*/
										echo "<span class='titleCalendario'>Giornata " . $g->getGiornata()
											. " (" . $g->getGiornataA() . "&deg; di serie A)"
											. " - " . strtoupper($g->getCompetizione()) . "</span>"; 
										echo "<table border='0' cellspacing='1' cellpadding='0'>
											<tr>
												<td class='scontroHeader' style='width:110px'>Allenatore</td>
												<td class='scontroHeader' style='width:130px'>Squadra</td>
												<td class='scontroHeader' style='width:40px'>Voto</td>
												<td class='scontroHeader' style='width:70px'>Risultato</td>
												<td class='scontroHeader' style='width:40px'>Voto</td>
												<td class='scontroHeader' style='width:130px'>Squadra</td>
												<td class='scontroHeader' style='width:110px'>Allenatore</td>
												<td > &nbsp; </td>
											</tr>
										";
										for($r = 0; $r < $g->getNumScontri(); $r++){
											$s = $g->getScontro($r);
											$alt = $r%2;
											echo "<tr>
												<td class='scontro scontro_$alt'>" . $s->getAllenatoreCasa() . "</td>
												<td class='scontro scontro_$alt'>" . $s->getSquadraCasa() . "</td>
												<td class='scontro scontro_$alt'>" . $s->getVotoCasa() . "</td>
												<td class='scontro scontro_$alt' style='text-align:center'>" . $s->getRisultato() . "</td>
												<td class='scontro scontro_$alt'>" . $s->getVotoOspite() . "</td>
												<td class='scontro scontro_$alt'>" . $s->getSquadraOspite() . "</td>
												<td class='scontro scontro_$alt'>" . $s->getAllenatoreOspite() . "</td>
												<td>" . getNote("'" . str_replace("'", "\'", $s->getNote()) . "'") . "</td>
												</tr>
											
											";
										} //end for r
										echo "</table>
											</div><br /><br />";
									} //end for i
									if($mobile_phone == 0) echo "</div>";
									
									if($lastPlayedDay > 0){
										echo "
										<script language='javascript' type='text/javascript' >
											window.location.hash = 'giornata_$lastPlayedDay';
										</script>";
									}
								?>
								<!--</div> -->
							</td>
						</tr>							
					</table>

					
				</td>
			</tr>
			<tr>
				<td>
					<?php printFooter() ?>
				</td>
			</tr>
		</table>
		<div id='divNote' style='display:none; position:absolute; width:200; height:auto; 
			z-index:100;background-color:rgb(245,245,150); color:black; font-size:10px;
			padding: 5 5 5 5;'></div>
	</body>
</html>